<?
  require('functions.inc.php');

  //echo "<html><head></head><body style=\"height: 96%; margin: 0px; margin-top: 25px; margin-left: 8px; padding: 0px; background-color: #DDDDDD; display: flex; flex-direction: row; flex-wrap: wrap;\">";

  if (!isset($_SESSION['loggedin']))
  {
    eval("print(\"".gettemplate("logout")."\");");
  }

  switch($_GET['type'])
  {
    case 'praxis':
      $result = mysqli_query($_SESSION['db_connection'], "SELECT * FROM praxen WHERE id='".$_GET['id']."';");
      $row = mysqli_fetch_assoc($result);
      $prax_id = $row['id'];
      $name = $row['name'];
      $wartung = ($row['wartung'] ? "Ja" : "Nein");
      $id_addr = $row['adresse'];
      $id_contact = $row['contact'];

      $result = mysqli_query($_SESSION['db_connection'], "SELECT * FROM adresse WHERE id='".$id_addr."';");
      $row = mysqli_fetch_assoc($result);
      $addr_strasse = $row['strasse'];
      $addr_hausnr = $row['hausnr'];
      $addr_plz = $row['plz'];
      $addr_ort = $row['ort'];
      $addr_land = $row['land'];

      if ($result = mysqli_query($_SESSION['db_connection'], "SELECT * FROM contact WHERE id='".$id_contact."';"))
	  {
	    $contacts = "<table>";
		while ($row = mysqli_fetch_assoc($result))
		{
		  $contact_id = $row['id'];
		  $contact_typ = getcontactnumbertype($row['typ']);
		  $contact_value = $row['value'];
		  $contacts .= "<tr><td>".$contact_typ.":</td><td>".$contact_value."</td></tr>";
		}
		$contacts .= "</table>";
      }

	  if ($result = mysqli_query($_SESSION['db_connection'], "SELECT * FROM aerzte WHERE praxis='".$prax_id."';"))
	  {
	    $aerzte_ma = "<table>";
	    while ($row = mysqli_fetch_assoc($result))
		{
		  $aerzte_ma .= "<tr><td>".$row['titel']." ".$row['vorname']." ".$row['name']."</td></tr>";
		}
		$aerzte_ma .= "</table>";
	  }

      eval("print(\"".gettemplate("detail_praxis")."\");");
      exit;
    case 'arzt':
      $result = mysqli_query($_SESSION['db_connection'], "SELECT * FROM aerzte WHERE id='".$_GET['id']."';");
      $row = mysqli_fetch_assoc($result);
      $id = $row['id'];
      $titel = $row['titel'];
      $name = $row['name'];
      eval("print(\"".gettemplate("detail_arzt")."\");");
      exit;
  }

  //eval("print(\"".gettemplate("foot")."\");");
?>
